use rand::Rng;
use std::{cmp::Ordering, io};

fn main() {
    println!("Please guess the number:");

    let sec_number = rand::thread_rng().gen_range(1..101);
    println!("The secret number is: {}", sec_number);

    // let sec_number2 = rand::thread_rng().gen_range(1..100);

    loop {
        // println!("Please enter your guess:");

        let mut guess = String::new();
        io::stdin().read_line(&mut guess).expect("Error reading");
        let guess: u32 = match guess.trim().parse() {
            Ok(number) => number,
            Err(_) => {
                println!("Please enter a number");
                continue;
            }
        };

        println!("You guessed: {}", guess);
        println!("Please enter stupid pit");
        match guess.cmp(&sec_number) {
            Ordering::Less => println!("Less!"),
            Ordering::Greater => println!("Greater!"),
            Ordering::Equal => println!("Equal!"),
        }

        match guess.cmp(&sec_number) {
            Ordering::Less => println!("Too small"),
            Ordering::Greater => println!("Too large"),
            Ordering::Equal => {
                println!("You win");
                break;
            }
        }
    }
}
